Completed
Push — master ( 27e40b...b923a8 )
by Yannick
07:56
created

L.Marker.include._setPos   C

Complexity

Conditions 7
Paths 28

Size

Total Lines 26

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 7
c 0
b 0
f 0
nc 28
nop 1
dl 0
loc 26
rs 6.7272
1
/*
2
 * Based on comments by @runanet and @coomsie 
3
 * https://github.com/CloudMade/Leaflet/issues/386
4
 *
5
 * Wrapping function is needed to preserve L.Marker.update function
6
 */
7
(function () {
8
	var _old__setPos = L.Marker.prototype._setPos;
0 ignored issues
show
Bug introduced by
The variable L seems to be never declared. If this is a global, consider adding a /** global: L */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
9
	L.Marker.include({
10
		_updateImg: function (i, a, s) {
11
			a = L.point(s).divideBy(2)._subtract(L.point(a));
0 ignored issues
show
Bug introduced by
The variable L seems to be never declared. If this is a global, consider adding a /** global: L */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
12
			var transform = '';
13
			transform += ' translate(' + -a.x + 'px, ' + -a.y + 'px)';
14
			transform += ' rotate(' + this.options.iconAngle + 'deg)';
15
			transform += ' translate(' + a.x + 'px, ' + a.y + 'px)';
16
			i.style[L.DomUtil.TRANSFORM] += transform;
17
			i.style[L.DomUtil.TRANSFORM + 'Origin'] = '50% 50%';
18
		},
19
20
		_getShortestEndDegree: function (startDegrees, endDegrees) {
21
			var turnAngle = Math.abs(endDegrees - startDegrees);
22
			var turnAnglePositive = (endDegrees - startDegrees) >= 0;
23
			if (turnAngle <= 180) return endDegrees;
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
24
			var result = startDegrees + (360 - turnAngle) * (turnAnglePositive ? -1 : 1);
25
			return result;
26
		},
27
28
		setIconAngle: function (iconAngle) {
29
			// find shortest angle to turn over
30
			this.options.iconAngle = this._getShortestEndDegree(this.options.iconAngle || 0, iconAngle);
31
			if (this._map)
32
				this.update();
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
33
		},
34
35
		_setPos: function (pos) {
36
			if (this._icon)
37
				this._icon.style[L.DomUtil.TRANSFORM] = '';
0 ignored issues
show
Bug introduced by
The variable L seems to be never declared. If this is a global, consider adding a /** global: L */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
38
			if (this._shadow)
39
				this._shadow.style[L.DomUtil.TRANSFORM] = '';
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
40
41
			_old__setPos.apply(this,[pos]);
42
43
			if (this.options.iconAngle) {
44
				var defaultIcon = new L.Icon.Default();
45
				var a = this.options.icon.options.iconAnchor || defaultIcon.options.iconAnchor;
46
				var s = this.options.icon.options.iconSize || defaultIcon.options.iconSize;
47
				var i;
48
				if (this._icon) {
49
					i = this._icon;
50
					this._updateImg(i, a, s);
51
				}
52
				if (this._shadow) {
53
					if (this.options.icon.options.shadowAnchor)
54
						a = this.options.icon.options.shadowAnchor;
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
55
					s = this.options.icon.options.shadowSize;
56
					i = this._shadow;
57
					this._updateImg(i, a, s);
58
				}
59
			}
60
		}
61
	});
62
}());
63